<?php

/**
 * 课时详情
 */

namespace Qy\Controller;

use Common\Controller\BaseController;

class PeriodController extends BaseController {

    public function _initialize() {
        parent::_initialize();
        empty($this->iUserId) && $this->error("请登录!", -103);
    }

    //课时详情
    public function info() {
        echo '接口删除';
        die;
        $iPeriodId = I('period_id', 0, 'intval');
        $iUserId = $this->iUserId;
        $arrPeriodInfo = M()->table('qy_period p')->field('p.period_id,p.period_name,p.aliyun_video_id,p.video_duration,p.curriculum_id,p.chapter_id,c.specialty_id')
                ->join('qy_curriculum as c ON c.curriculum_id=p.curriculum_id')
                ->where(array('period_id' => $iPeriodId))
                ->find();

        //不在企业，不用记录
        $iCompanyId = $this->iCompanyId;
        if (empty($iCompanyId)) {
            $this->returnList($arrPeriodInfo);
        }

        $objUserPeriodRecord = M('UserPeriodRecord');
        //1. 插入学习记录表
        $arrWhere = array(
            'user_id' => $iUserId,
            'company_id' => $iCompanyId,
            'period_id' => $iPeriodId,
            'curriculum_id' => $arrPeriodInfo['curriculum_id'],
            'chapter_id' => $arrPeriodInfo['chapter_id'],
            'post_id' => $this->iPostId,
            'create_time' => array('between', array(date('Y-m-d 00:00:00'), date('Y-m-d 23:59:59')))
        );
        $iCount = $objUserPeriodRecord->where($arrWhere)->count();
        if ($iCount == 0) {
            $arrData = $arrWhere;
            $arrData['create_time'] = date("Y-m-d H:i:s");
            $objUserPeriodRecord->add($arrData);
        }

        $this->returnList($arrPeriodInfo);
    }

}
